#include "CMesh.h"
#include "GameSceneManager.h"
#include "GameObjectManager.h"

comp_id_type CMesh::mFamilyID = "CMesh";
comp_id_type CMesh::mComponentID = "CMesh";

comp_id_type CMeshTemplate::mFamilyID = "CMesh";
comp_id_type CMeshTemplate::mComponentID = "CMesh";

//Ogre::String CMesh::meshFileName = "";
//Ogre::String CMeshTemplate::meshFileName = "";

CMeshTemplate::CMeshTemplate() {

}
CMeshTemplate::CMeshTemplate(Ogre::String meshName = "") {
	meshFileName = meshName;
}
CMeshTemplate::~CMeshTemplate() {

}
GameComponent *CMeshTemplate::makeComponent() {
	CMesh *comp = new CMesh(this);
	return comp;
}

CMesh::CMesh()
{

}
CMesh::CMesh(Ogre::String meshName = "")
{
	if(meshName!="") {
		std::string name;
		name = "CMeshComponent" + StringConverter::toString(GameObjectManager::getSingleton()->getNextCompIndex());
		meshFileName = meshName;
		mEntity = GameSceneManager::getSingleton()->getSceneManager()->createEntity(name,meshName);

		//MaterialPtr material (MaterialManager::getSingleton().getByName("ETTerrainMaterial"));
		//GameSceneManager::getSingleton()->getSceneManager()->setMaterial(material);

	}
}
CMesh::CMesh(CMeshTemplate *templ)
{

}
CMesh::~CMesh()
{
	//ResourceGroupManager::getSingleton().er
	mEntity->_deinitialise();
	delete mEntity;
}

void CMesh::update() {

}

void CMesh::setup() {
	//This is to keep track of objects, when i cast rays on meshes, i get the name of the owner
	std::string objectName;
	objectName = getOwnerObject()->getID().c_str();

	mEntity->setUserAny( Ogre::Any(objectName) );
	
}
